package csu.web.mypetstore.web.servlet;

import csu.web.mypetstore.domain.Account;
import csu.web.mypetstore.domain.History;
import csu.web.mypetstore.domain.Item;
import csu.web.mypetstore.domain.Product;
import csu.web.mypetstore.persistence.AccountDao;
import csu.web.mypetstore.persistence.impl.AccountDaoImpl;
import csu.web.mypetstore.service.CatalogService;

import javax.servlet.Filter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class ItemFormServlet extends HttpServlet {
    private CatalogService catalogService;

    private static final String ITEM_FORM="/WEB-INF/jsp/catalog/item.jsp";

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       /*String itemId=req.getParameter("itemId");
       catalogService=new CatalogService();
       Item item=catalogService.getItem(itemId);
        Product product=item.getProduct();

        HttpSession session=req.getSession();

        String isAdd=null;
        session.setAttribute("isAdd","true");

//添加日志功能

        session.setAttribute("product", product);
        session.setAttribute("item", item);

        String productName=product.getName();
        String itemName=item.getItemId();

        Account account = (Account) session.getAttribute("loginAccount");
        AccountDao accountDao=new AccountDaoImpl();



        if(account!=null){
            boolean history=accountDao.findHistoryByUsernameandCategory(account.getUsername(),itemName);

            History history1=accountDao.getHistoryByUsername(account.getUsername(),itemName);
            if(!history || history1.getVisittimes()==0){//找不到时
                accountDao.insertHistroyUserId(account,itemName);
                accountDao.InitVisitNum(account,itemName);
                accountDao.initCartVisitNum(account,itemName);
                accountDao.insertHistroyUser(account,itemName);
                accountDao.UpdateVisitNum(account,itemName);

            }else{
                accountDao.UpdateVisitNum(account,itemName);
            }
        }

*/


        req.getRequestDispatcher(ITEM_FORM).forward(req, resp);
    }


}
